<?php
session_start();
include("../includes/conn.php");
$dbconn->admin_logincheck();
$pro_name =  isset($_GET['name'])?$_GET['name']:'';
$credit = isset($_GET['credit'])?$_GET['credit']:'';
$time = isset($_GET['time'])?$_GET['time']:'';
$where = '1';
if($pro_name)
{
	$where .= ' and '.DBQIAN.'buylog.product_name like \'%'.$pro_name.'%\'';
}
if ($time)
{
	$where .= ' and '.DBQIAN.'buylog.create_time >=\''.$time.'\' and '.DBQIAN.'buylog.create_time <=\''.substr($time,0,10).' 23:59:59\'';
}
//echo $where;exit;
if($_GET['act']=='close'){
	$id=intval($_GET['id']);
	$dbconn->noretquery("update ".DBQIAN."buylog set status=8 where id=$id");
	$yh_price = mysql_fetch_array($dbconn->query("select yh_price,openid from ".DBQIAN."buylog where id =$id"));
	$result = $dbconn->query("update ".DBQIAN."users set credit=credit+".$yh_price['yh_price']." where openid='".$yh_price['openid']."'");
}
?><!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>欢迎登录后台管理系统</title>
<link href="css/base.css" rel="stylesheet" type="text/css" />
<link href="css/right.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="css/tab.css" media="all" />
<link rel="stylesheet" type="text/css" href="css/css/font-awesome.min.css" />
<script language="JavaScript" src="js/jquery2.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/jquery-ui-slide.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="js/bootstrap-tab.js"></script>
<script>
$(document).ready(function(){
	
   $(function(){
		$("#time").datetimepicker();
      	$(".rightinfo tbody tr:odd").css("backgroundColor","#f5f8fa");
      	$("#gengduo").click(function (){
      		$(".dropdown-menu").toggle();
        });
      	$("#ship").click(function(){
        	location.href="ordership.php";
        });
        $("#shiped").click(function(){
        	location.href="ordershiped.php";
        })
        $("#pay").click(function(){
        	location.href="orderpay.php";
        })
        $("#payed").click(function(){
        	location.href="orderpayed.php";
        })
        $("#all").click(function(){
        	location.href="orderlist.php";
        })
   });
});
  $(function(){
    	$("#myTab a").click(function (e) {
      	e.preventDefault();
      	$(this).tab("show");
    })
  });
</script>
</script>
<style type="text/css">
.ui-timepicker-div .ui-widget-header { margin-bottom: 8px;}
.ui-timepicker-div dl { text-align: left; }
.ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }
.ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }
.ui-timepicker-div td { font-size: 90%; }
.ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }
.ui_tpicker_hour_label,.ui_tpicker_minute_label,.ui_tpicker_second_label,.ui_tpicker_millisec_label,.ui_tpicker_time_label{padding-left:20px}
.tablelist td {	line-height:35px;text-indent:0px;border-right: dotted 1px #c7c7c7;}
</style>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li><a href="index.php">首页</a></li>
    <li>订单管理</li>
  </ul>
</div>
<div class="rightinfo">
	<div>
	<form action="" method="get" style="font-size:14px;font-weight:bolder;">
		购买产品: <input type="text" name="name" value="<?=$_GET['name']?>" size="25" placeholder="产品名称" style="text-align:center;border:1px solid #000;height:28px;border-radius:4px; background:#eeeeee;" /> &nbsp;&nbsp;
		创建时间: <input type="text" name="time" id="time" value="<?=$_GET['time']?>" size="30" placeholder="" style="text-align:center;border:1px solid #000;height:28px;border-radius:4px;background:#eeeeee;" /> &nbsp;&nbsp;
		<input type="submit" name="submit" value="查询" style="width:60px; text-align:center;border:1px solid #000;height:28px;border-radius:4px; background:#b6cad2;" /> &nbsp;&nbsp;
	</form><br/>
	</div>
<!--   <div class="tools">  -->
<!--     <ul class="toolbar"> -->
<!-- 	  <li><a href="product_add.php"><span><img src="images/t01.png" /></span>上架商品</a></li>  -->
      <!--<li><a href="excel.product.php"><span><img src="images/ico03.png" /></span>导出</a></li> -->
      <!--<li><a onClick="if(confirm(\'您确认要清空吗？\')){location.href=\'?act=trucate\'}" href="#"><span><img src="images/t03.png" /></span>清空记录</a></li>-->

<!--     </ul> -->
<!--   </div> -->
				
	<section class="demo">
		<ul class="nav nav-tabs" id="myTab">
		  <li id="all"><a href="#home">所有订单</a></li>
		  <li id="ship"><a href="#profile">待发货</a></li>
		  <li id="shiped"><a href="#message">已发货</a></li>
		  <li id="payed"><a href="#settings">已付款</a></li>
		  <li id="pay" class="active"><a href="#paydiv">未付款</a></li>
		</ul>
		 
		<div class="tab-content">
		  <div class="tab-pane active" id="home">
		  	<table class="tablelist">
			    <thead>
			      <tr>
			        <th align="center" width="8%">产品名称</th>
			        <th align="center" width="3%">产品图片</th>
					<th align="center" width="3%">购买数量</th>
					<th align="center" width="3%">用户</th>
					<th align="center" width="4%">订单状态</th>
					<th align="center" width="5%">支付状态</th>
			        <th align="center" width="5%">创建时间</th>
			        <th align="center" width="14%">操作</th>
			      </tr>
			    </thead>
			    <tbody>
<?php 
$page = ($_GET['page'] == ''||!isset($_GET['page'])) ?1:$_GET['page'];
$pagesize=12;
$where .= ' and '.DBQIAN.'buylog.paystatus=0';//未支付订单
$num1=$dbconn->countn(DBQIAN."buylog",$where);//获取数据条数
$pagelist2 = new page($page,$pagesize,$num1 ,10,2,0);
$where = str_replace('yifenduohao_buylog', 'b', $where);
$sql = " select b.*,p.img,u.name as realname from ".DBQIAN."buylog b join ".DBQIAN."product p on b.product_id=p.id join ".DBQIAN."users u on b.users_id=u.id where ".$where." order by create_time desc ";
// echo $sql;exit;
$query=$dbconn->news_list($sql,$page,$pagesize);
while($row=$dbconn->fetch($query))
{
	$orderstatus = '';
	switch ($row['status'])
	{
		case 1: $orderstatus='<font color="brown">未支付</font>';break;
		case 2: $orderstatus='<font color="red">待发货</font>';break;
		case 3: $orderstatus='<font color="brown">未支付</font>';break;
		case 4: $orderstatus='<font color="#046dbb">待收货</font>';break;
		case 5: $orderstatus='<font color="red">待发货</font>';break;
		case 6: $orderstatus='<font color="green">交易完成</font>';break;
		case 7: $orderstatus='<font color="gray">关闭</font>';break;
		case 8: $orderstatus='<font color="gray">卖家关闭</font>';break;
	}
	echo'<tr height="45">
        <td title="">'.$row['product_name'].'</td>
        <td><img src="../user/'.$row['img'].'" width="32px"/></td>
        <td>'.$row['quantity'].'</td>
        <td>'.$row['realname'].'</td>	
        <td>'.$orderstatus.'</td>	
        <td>'.($row['paystatus']?'<font color="green">已支付</font>':'<font color="gray">未支付</font>').'</td>	
        <td>'.$row['create_time'].'</td>
        <td>
		<i class="fa fa-1x fa-file-text-o"></i>
		<a onClick="window.location.href=\'orderdetail.php?act=detail&id='.$row['id'].'&page='.$page.'\'" href="#" class="tablelink">详情</a>
         <img src="images/ice.png" width="14"> 
          <a onClick="window.location.href=\'orderedit.php?act=edit&id='.$row['id'].'&page='.$page.'\'" href="#" class="tablelink">编辑</a>
         <img src="images/t03.png" width="14">'. (($row['status']==7 || $row['status']==8)?'<a style="color:gray">关闭订单</a>':' 
          <a onClick="if(confirm(\'您确认要关闭该订单吗？\')){window.location.href=\'?act=close&id='.$row['id'].'&page='.$page.'\'}" href="#" class="tablelink">关闭订单</a>').'
        </td>
	  </tr>';
}
?>
				</tbody>
			  	</table>
			  	<div style=" width:90%; padding:10px 0 10px 0; text-align:center">
				<?php 
				if($num1!=0) 
					echo $pagelist2->showpages();
				else 
					echo "<font color='#ff0000'>暂无数据</font>";
				?>
				</div>
		  </div>
		  <div class="tab-pane" id="profile">
				
		  </div>
		  <div class="tab-pane" id="messages"></div>
		  <div class="tab-pane" id="settings"></div>
		  <div class="tab-pane" id="settings"></div>
		  <div class="tab-pane" id="settings"></div>
		</div>
	</section>
				
  
</div>
</body>
</html>